package action.chap6;

import action.chap4.Dish;
import action.chap4.DishUtils;

import java.util.Comparator;
import java.util.List;
import java.util.Optional;

import static java.util.stream.Collectors.*;


public class Demo621 {
    public static void main(String[] args) {
        List<Dish> listDish =
                DishUtils.getListDish();
        // 求出最大值的
        Optional<Dish> collect = listDish.stream().max(Comparator.comparingInt(Dish::getCalories));
        Dish dish = collect.get();
        System.out.println(dish.getCalories());
        //求和1
        Integer collect2 = listDish.stream().mapToInt(Dish::getCalories).sum();
        System.out.println(collect2);
        //求和2
        Integer collect1 = listDish.stream().mapToInt(Dish::getCalories).sum();
        System.out.println(collect1);
        //求平均值

        Double collect3 = listDish.stream().collect(averagingInt(Dish::getCalories));
        System.out.println(collect3);

    }
}
